﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LightCube
{
    public abstract class LightCubeBase
    {
        private Buffer3D buffer;
        private SerialPortDriver driver;
        
        public LightCubeBase(int size)
        {
            buffer = new Buffer3D(size);
            driver = new SerialPortDriver();
        }

        public void Connect(string port)
        {
            driver.Connect(port);
        }

        public void Disconnect()
        {
            driver.Disconnect();
        }

        public void Clear()
        {
            buffer.Clear();
            driver.Clear();
        }

        public void Draw(Point3D point,  LightColor color)
        {
            buffer.SetPixel(point, color);
        }

        public bool DrawSceneFrame(IScene scene)
        {
            return scene.DrawFrame(buffer);
        }

        public void Flush()
        {
            var frame = EncodeFrame(buffer);
            driver.DrawFrame(frame);

            buffer.Clear();
        }

        public abstract byte[] EncodeFrame(Buffer3D buffer);

        public void StartRecording()
        {
            driver.StartRecording();
        }

        public void StopRecording()
        {
            driver.StopRecording();
        }

        public void PlayRecording()
        {
            driver.PlayRecording();
        }
    }
}